package implementor;

import java.sql.SQLException;



import dao.EmployeeDao;
import dbhandelling.Crude;
import dto.Employee;

public class EmployeeImpl extends Crude implements EmployeeDao{

	String className=new Employee().getClass().getName();
	@Override
	public void add(Employee emp) throws SQLException, Exception {
			super.insert(emp);
		
	}

	@Override
	public void update(Employee emp) throws Exception {
		super.update(className, "employeeName",emp.getEmployeeName(), "autoEmployeeId", emp.getAutoEmployeeId()+"");
		super.update(className, "employeeDesignation",emp.getEmployeeDesignation(), "autoEmployeeId", emp.getAutoEmployeeId()+"");
		super.update(className, "joinedAt",emp.getJoinedAt()+"", "autoEmployeeId", emp.getAutoEmployeeId()+"");
		super.update(className, "leftAt",emp.getLeftAt()+"", "autoEmployeeId", emp.getAutoEmployeeId()+"");
		super.update(className, "employeeAddress",emp.getemployeeAdreess(), "autoEmployeeId", emp.getAutoEmployeeId()+"");
		super.update(className, "employeePhone",emp.getEmployeePhone()+"", "autoEmployeeId", emp.getAutoEmployeeId()+"");
		super.update(className, "employeeStatus",emp.getEmployeeStatus()+"", "autoEmployeeId", emp.getAutoEmployeeId()+"");
		
	}

	@Override
	public void delete(Employee emp) throws Exception {
		super.delete(className,  "autoEmployeeId", emp.getAutoEmployeeId()+"");
		
	}

	@Override
	public Employee retreive(String conditionField, String conditionValue)
			throws Exception {
		
		Employee e=(Employee) super.retreive(className, conditionField, conditionValue);
		return e;
	}

	@Override
	public Employee[] retreiveArray(String conditionField, String conditionValue)
			throws Exception {
		Object[] employee= super.retreiveArrayOnCondition(className, conditionField, conditionValue);
		Employee[] s=new Employee[employee.length];
		
		for(int i=0;i<s.length;i++)
			s[i]=(Employee) employee[i];
		return s;
	}

	@Override
	public Employee[] retreiveAll() throws Exception {
		Object[] employee= super.retreiveAll(className);
		Employee[] s=new Employee[employee.length];
		
		for(int i=0;i<s.length;i++)
			s[i]=(Employee) employee[i];
		return s;
	}

}
